//
//  SFDiscoverSearchView.swift
//  SFWeiBo
//
//  Created by 孙凡 on 16/4/7.
//  Copyright © 2016年 Edward. All rights reserved.
//

import UIKit

class SFDiscoverSearchView: UIView {



    /**文本框右边的约束*/
    @IBOutlet weak var rightConstraint: NSLayoutConstraint!

    @IBOutlet weak var textFiled: UITextField!

    @IBOutlet weak var cancleBtn: UIButton!

    /**

     @IBInspectable

     @IBDesignable

     */




    override func awakeFromNib() {

        self.textFiled.placeholder = "听说下雨天和裸奔更配哟"

        leftView.frame.size = CGSizeMake(self.frame.height, self.frame.height)
        self.textFiled.leftView = leftView
        self.textFiled.leftViewMode = UITextFieldViewMode.Always

        //设置边框
//        self.textFiled.layer.borderWidth = 5
//        self.textFiled.layer.borderColor = UIColor.orangeColor().CGColor
//        self.textFiled.layer.cornerRadius = 10
//        self.textFiled.layer.masksToBounds = true


    }

    class func searchView() -> SFDiscoverSearchView{

        return NSBundle.mainBundle().loadNibNamed("SFDiscoverSearchView", owner: nil, options: nil).last! as! SFDiscoverSearchView

    }

    @IBAction func beginEdting(sender: AnyObject) {

        self.rightConstraint.constant += self.cancleBtn.frame.width

        UIView.animateWithDuration(1.0) {

            self.textFiled.layoutIfNeeded()
        }
    }

    @IBAction func cancleBtnDidClick(sender: AnyObject) {

        self.rightConstraint.constant = 0

        UIView.animateWithDuration(1.0) {

            self.textFiled.layoutIfNeeded()
        }

        self.textFiled.resignFirstResponder()

    }


    //懒加载控件
    private lazy var leftView: UIImageView = {

        let view = UIImageView.init(image: UIImage.init(named: "searchbar_textfield_search_icon"))

        view.contentMode = UIViewContentMode.Center

        return view
    }()

}
